package com.cn.example.demo.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.cn.example.demo.beans.TestBean;

@RestController
public class TestController {
	private final Logger logger = LogManager.getLogger(TestController.class);

	/**
	 * -测试该框架能否能用-
	 * 
	 * @return
	 */
	@RequestMapping(value = "/hello", method = RequestMethod.GET)
	public String showTime() {
		SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
		String time = sDateFormat.format(new Date());
		logger.info("---->Api[/hello]被调用。。。");
		logger.info("time="+time);		
		return time;
	}
	
	/**
	 * -测试restfulResult是否生效-
	 * 
	 * @return
	 */
	@RequestMapping(value = "/maprestful", method = RequestMethod.GET)
	public Map<String, Object> maprestful() {
		logger.info("---->Api[/maprestful]被调用。。。");		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "接口");
		map.put("value", "/maprestful");
		map.put("time", new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(new Date()));
		return map;
	}
	
	/**
	 * -测试restfulResult是否生效-
	 * 
	 * @return
	 */
	@RequestMapping(value = "/listrestful", method = RequestMethod.GET)
	public List<TestBean> restful() {
		logger.info("---->Api[/listrestful]被调用。。。");
		List<TestBean> list = new ArrayList<>();
		list.add(new TestBean("接口","/listrestful", new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(new Date())));
		return list;
	}
	
	/**
	 * -测试restfulResult是否生效-
	 * 
	 * @return
	 */
	@RequestMapping(value = "/listmaprestful", method = RequestMethod.GET)
	public List<Map<String, Object>> listmap() {
		logger.info("---->Api[/listmaprestful]被调用。。。");		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("name", "接口");
		map.put("value", "/listmaprestful");
		map.put("time", new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(new Date()));
		List<Map<String, Object>> list = new ArrayList<>();
		list.add(map);
		list.add(map);
		return list;
	}

	/**
	 * -测试restfulResult是否生效-
	 * 
	 * @return
	 */
	@RequestMapping(value = "/beanrestful", method = RequestMethod.GET)
	public TestBean beanrestful() {
		logger.info("---->Api[/beanrestful]被调用。。。");		
		return new TestBean("接口", "/beanrestful", new SimpleDateFormat("yyyy/MM/dd hh:mm:ss").format(new Date()));
	}
}
